#include <string>
#include <iostream>
#include <sys/time.h>
using namespace std;


#define OUT_REPEATE_NUM 10000
#define IN_REPEATE_NUM 6

string s1 = "abcdefg";
string s2 = "hijklmn";
string s3 = "opqrstu";

void testPlus1(string& res){
    for(int i = 0; i < IN_REPEATE_NUM; ++i){
        res += s1;
        res += s2;
        res += s3;
    }
}

void testAppend(string& res){
    for(int i = 0; i < IN_REPEATE_NUM; ++i){
        res.append(s1);
        res.append(s2);
        res.append(s3);
    }
}

void testPlus2(string& res){
    for(int i = 0; i < IN_REPEATE_NUM; ++i){
        res = s1 + res;
        res = s2 + res;
        res = s3 + res;
    }
}

int main(int argc, char const *argv[])
{
    string plus1, plus2, append;
    timeval sTime, eTime;

    gettimeofday(&sTime, NULL);
    testPlus1(plus1);
    gettimeofday(&eTime, NULL);
    cout << (eTime.tv_sec - sTime.tv_sec) * 1000000 + (eTime.tv_usec - sTime.tv_usec) << endl;

    gettimeofday(&sTime, NULL);
    testPlus1(plus2);
    gettimeofday(&eTime, NULL);
    cout << (eTime.tv_sec - sTime.tv_sec) * 1000000 + (eTime.tv_usec - sTime.tv_usec) << endl;

    gettimeofday(&sTime, NULL);
    testPlus1(append);
    gettimeofday(&eTime, NULL);
    cout << (eTime.tv_sec - sTime.tv_sec) * 1000000 + (eTime.tv_usec - sTime.tv_usec) << endl;

    return 0;
}





